<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="jiesuan"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
        	<div class="layui-card-body">
		      		<fieldset class="layui-elem-field layui-field-title">
							  <legend>申请结算列表</legend>
							</fieldset>
		      </div>
          <div class="layui-card-body">
          		
            <Tables
              :fdate="pdate"
              :result="res"
              height="430"
              :totalCount="totalRows"
              :pageNumber="curindex"
              :fbtn="btn"
            ></Tables>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../common/pagetop.vue";
import Secondnav from "../common/secondnav.vue";
import Tables from "../common/tables.vue";
import Search from "../common/search.vue";
export default {
  name: "gradelist",
  components: { Pagetop, Secondnav, Tables, Search },
  data() {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      type: localStorage.getItem("type"),
    };
  },
  mounted() {
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      var url = "/pay/bapi/v1.9/settlement/settlementApplyPage";
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          dates[res[i].key + ".equals"] = res[i].val;
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          sort:'createAt,DESC',
          //'status.equals':'ENABLE'
        };
      }
      //alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(dourl(url), "GET", "json", dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: "id", title: "ID" },
          { field: "dealerName", title: "商家名称 "},
          {
            field: "orderPayAmount",
            title: "应结订单金额(元)",
            templet: function (d) {
              return d.orderPayAmount / 100;
            },
          },
          {
            field: "refundAmount",
            title: "退款金额(元)",
            templet: function (d) {
              return d.refundAmount / 100;
            },
          },
          {
            field: "serviceCharge",
            title: "手续费金额(元)",
            templet: function (d) {
              return d.serviceCharge / 100;
            },
          },
          {
            field: "settleAmount",
            title: "应结算总额",
            templet: function (d) {
              return d.settleAmount / 100;
            },
          },
          {
            field: "settlementType",
            title: "结算方式",
            templet: function (d) {
              return d.settlementType=='TRANSFER'?'银行卡转账':'线下打款';
            },
          },
          {
            field: "reson",
            title: "驳回原因 "
          },
          {
            field: "authStatus",
            title: "审核状态 ",
            templet: function (d) {
              if(d.authStatus=='NOTYET'){
              	return '待审核'
              }
              else if(d.authStatus=='PASS'){
              	return '审核通过'
              }
              else if(d.authStatus=='FAIL'){
              	return '审核不通过'
              }
              else if(d.authStatus=='CANCEL'){
              	return '取消'
              }
            }
          },
          {
            field: "authAt",
            title: "审核时间 ",
            templet: function (d) {
              return FormatDate(d.authAt)
            }
          },
          {
            field: "right",
            title: "操作",
            width: "250",
            fixed: "right",
            templet: function (d) {
            	if(_this.type!=1){
		              var str =
		                '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">完善银行卡信息</a>';
		             if(d.authStatus=='NOTYET'){
				         	str=str+'<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">取消</a>';
				         }
		          }
            	else{
            		var str = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="pay">审核</a>';
            	}
		         str=str+'<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="enable">详情</a>';
              return str;
            },
          },
        ];
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.page + 1;
      });
    },
    getsearch: function () {
      var arr = [{ field: "id", title: "ID", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
   
   
    editInfo: function (data) {
      var _this = this;
      layer.confirm('是否新增银行卡？', {
			  btn: ['新增银行卡','选择已有的卡'] //按钮
			}, function () {
				layer.open({
	        type: 2,
	        title: "新增银行卡信息",
	        content: baseurl + "/yhkadd",
	        area: _this.screens() < 2 ? ["80%", "65%"] : ["800px", "650px"],
	        success: function (layero, index) {
	         	var iframeWin = window[layero.find('iframe')[0]['name']];
        		iframeWin.getdates(data);
	        },
	      });
			}, function(){
				layer.open({
	        type: 2,
	        title: "选择银行卡信息",
	        content: baseurl + "/juesuanadd",
	        area: _this.screens() < 2 ? ["80%", "65%"] : ["800px", "650px"],
	        success: function (layero, index) {
	         	var iframeWin = window[layero.find('iframe')[0]['name']];
        		iframeWin.getdates(data);
	        },
	      });
			});
      
    },
    delInfo:function(data){
    	var url='/pay/bapi/v1.9/settlement/updateApplyCancel'
    	var dates={
    		id:data.id
    	}
    	var _this=this;
    	ajaxRequest(url,'PUT','json',dates,function(ret,err){
				layer.msg("操作成功");
			  setTimeout(function(){
			  	_this.getdate()
	      },1000)
			})
    },
    enableInfo:function(data){
    	var _this = this;
			layer.open({
        type: 2,
        title: "查看结算详情",
        content: baseurl + "/jsdetail",
        area: _this.screens() < 2 ? ["80%", "65%"] : ["800px", "650px"],
        success: function (layero, index) {
         		var iframeWin = window[layero.find('iframe')[0]['name']];
        		iframeWin.getdates(data);
        },
      });
	  },
	  payInfo:function(data){
	  	var _this = this;
			layer.open({
        type: 2,
        title: "审核",
        content: baseurl + "/jsconfirm",
        area: _this.screens() < 2 ? ["80%", "65%"] : ["800px", "650px"],
        success: function (layero, index) {
         		var iframeWin = window[layero.find('iframe')[0]['name']];
        		iframeWin.getdates(data);
        },
      });
	  },
    screens: function () {
      return screen();
    },
  },
  updated: function () {
    this.isShow = true;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
    });
  },
};
</script>
<style scoped>
/**/
</style>